home *** CD-ROM | disk | FTP | other *** search
/ Network CD 1 / Network CD.iso / others / emit / emit20.lzh / aprintf.asm next >
Assembly Source File  |  1988-01-30  |  3KB  |  98 lines

  1. * ------------------------------------------------------------------------- *
  2. * Aprintf.asm
  3. * Copyright Justin V. McCormick 1988
  4. * ------------------------------------------------------------------------- *
  5.     TTL    aprintf.asm
  6.  
  7.     SECTION    aprintf,CODE
  8.  
  9.     NOLIST
  10.     include "macros.i"
  11.  
  12. ;    include "libraries/dos_lib.i"
  13. ;    include    "exec/exec_lib.i"
  14.  
  15. * Equates replacing above files includes
  16. _LVORawDoFmt    EQU    $FFFFFDF6
  17. _LVOWrite    EQU    $FFFFFFD0
  18.  
  19.     LIST
  20.  
  21. * Externals
  22.     XREF    _cliout        ;CLI standard output filehandle, LONG
  23.     XREF    _DOSBase    ;Pointer to DOSBase, LONG
  24. * ------------------------------------------------------------------------- *
  25. * void aprintf(formatstring, args)
  26. *   char *formatstring;
  27. *   char **args;
  28. * Synopsis: Given formatstring and args to format, prints output to current
  29. * terminal output channel, globally defined as _cliout, where:
  30. *   LONG cliout;
  31. *   cliout = Output();
  32. *   
  33. * No error checking is performed for cliout pointing to a valid filehandle,
  34. * i.e., you must initialize cliout before calling aprintf().  _DOSBase must
  35. * be initialized as:
  36. *   struct DOSBase *DOSBase;
  37. *   DOSBase = (struct DOSBase *)OpenLibrary("dos.library", 33L);
  38. * ------------------------------------------------------------------------- *
  39.     XDEF    _aprintf
  40. _aprintf:
  41.     link    a5,#-512        ;Allocate 512 bytes on stack
  42.     movem.l    d0/d1/a0-a3,-(sp)    ;Save everything we might clobber
  43.  
  44. * Call format function to convert fmtstring and args to buffer on the stack
  45.     movea.l    8(a5),a0        ;Grab format string
  46.     lea    12(a5),a1        ;Grab EA of arguments
  47.     lea    kput1(pc),a2        ;Grab EA of output subroutine
  48.     lea    -512(a5),a3        ;Grab EA of temp workspace
  49.     SYS    RawDoFmt,4        ;Format it into workspace
  50.  
  51. * Calculate length of resulting string, output to console CLI
  52.     lea    -512(a5),a0        ;a0 = Start of buffer
  53.     move.l    a0,d2            ;Copy for output
  54.     bsr.s    astrlen            ;Calculate string length
  55.     move.l    d0,d3            ;length of string
  56.     move.l    _cliout,d1        ;Filehandle
  57.     SYS    Write,_DOSBase        ;Dump the string to stdout
  58.     
  59.     movem.l    (sp)+,d0/d1/a0-a3    ;Restore registers
  60.     unlk    a5            ;And stack frame
  61.     rts
  62.  
  63. * ------------------------------------------------------------------------- *
  64. * RawDoFmt() output routine for aprintf, called for each formatted char.
  65. * Takes byte in d0 and puts in buffer pointed to by a3, then increments a3.
  66. * ------------------------------------------------------------------------- *
  67.     XDEF    kput1
  68. kput1:
  69.     move.b    d0,(a3)+
  70.     rts
  71.  
  72. * ------------------------------------------------------------------------- *
  73. * LONG astrlen(string)
  74. *  d0            a0
  75. *   char *string;
  76. *
  77. * Synopsis: Calculate length of null-byte terminated string.
  78. * Modifies: d0 = length of string, a0 = next byte address after zero byte.
  79. * ------------------------------------------------------------------------- *
  80.     XDEF    astrlen
  81. astrlen:
  82.     moveq    #0,d0        ;Clear count
  83. 1$
  84.     tst.b    (a0)+        ;Test a byte for zero-ness
  85.      beq.s    2$        ;Found it! return length
  86.     
  87.     addq.w    #1,d0        ;Otherwise bump count
  88.      bra.s    1$        ;Check next byte
  89.  
  90. 2$
  91.     rts
  92.  
  93. * ------------------------------------------------------------------------- *
  94.     END
  95.